# -*- coding: utf-8 -*-
"""
# @created on : 9月 2021/9/26 09:03
# @author     : kevin
# @file       : path.py
# @software   : PyCharm
# @project    : auto_keyword_data


@license: (C) Copyright 2019-2025, Corporation Limited.
@desc:
"""
import os


class OperationPath:
    def __init__(self, file='__file__'):
        self.file = file

    def get_current_path(self):
        """
        获取当前文件所在的路径
        :return:当前文件路径
        """
        current_path = os.path.split(os.path.realpath(self.file))[0]
        return current_path

    def get_parent_path(self):
        """
        获取当前文件所在路径的父路径
        :return:父路径
        """
        parent_path = os.path.split(self.get_current_path())[0]
        return parent_path

    def check_path(self, path):
        """
        检查传入的文件路径是否存在，如果不存在则建立相应目录
        :param path:
        :return:
        """
        from common.log import Logger

        if not os.path.exists(path):
            os.makedirs(path)
            Logger().logger('info', f'创建目录"{path}"成功!')

    def check_file(self, file):
        flg = False
        if os.path.exists(file):
            flg = True

        return flg
